package com.controller.cook;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.po.CookL;
import com.po.OrderL;
import com.service.cook.CookServiceL;

@Controller
public class CookControllerL {
	
	@Resource(name="cookServiceImpL")
	private CookServiceL cookservice;
	
	@ResponseBody
	@RequestMapping(value="/addCookL")
	public int addCook(@RequestBody CookL cook){
		int result = 0;
		CookL co = cookservice.findCookInfo(cook);
		if(co!=null)
			result = cookservice.addCook(cook);
		return result;
	}
	/*public int addCook(@RequestBody Cook cook,HttpServletRequest request){
		request.getSession().getAttribute("username");
		if 
		return cookservice.addCook(cook);
	}*/
	@ResponseBody
	@RequestMapping(value="/findCookInfoL")
	public int findCookInfo(@RequestBody CookL cook){
		CookL co = cookservice.findCookInfo(cook);
		if(co!=null){
			return 1;
		}else{
			return 0;
		}
	}
	
	@ResponseBody
	@RequestMapping(value="/getOrderListL")
	public List<OrderL> getOrderList(){
		
		return (List<OrderL>)cookservice.getOrderList();
	}
	@ResponseBody
	@RequestMapping(value="/findOrderListInfoByIdL")
	public List<OrderL> getOrderListInfoById(@RequestBody OrderL order){
		
		return (List<OrderL>)cookservice.getOrderListInfoById(order);
	}
	
	@ResponseBody
	@RequestMapping(value="/getOrderListNoCheckL")
	public List<OrderL> getOrderListNoCheck(){
		
		return (List<OrderL>)cookservice.getOrderListNoCheck();
	}
	@ResponseBody
	@RequestMapping(value="/getOrderListNoCheckInfoByIdL")
	public List<OrderL> getOrderListNoCheckInfoById(@RequestBody OrderL order){
		
		return (List<OrderL>)cookservice.getOrderListNoCheckInfoById(order);
	}
	
	@ResponseBody
	@RequestMapping(value="/getOrderListByStatusL")
	public List<OrderL> getOrderListByStatus(@RequestBody OrderL order){
		if(" ".equals(order.getOrder_status())){
			return (List<OrderL>)cookservice.getOrderList();
		}else{
			return (List<OrderL>)cookservice.getOrderListByStatus(order);
		}
	}
	

	@ResponseBody
	@RequestMapping(value="/getOrderListByDateL")
	public List<OrderL> getOrderListByDate(String order){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		System.out.println("现在的系统时间为：：："+sdf.format(new Date()));
		return (List<OrderL>)cookservice.getOrderListByDate(sdf.format(new Date()));
	}
	@ResponseBody
	@RequestMapping(value="/getOrderListByDateInfoByIdL")
	public List<OrderL> getOrderListByDateInfoById(@RequestBody OrderL order){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		order.setOrder_eattime(sdf.format(new Date()));
		return (List<OrderL>)cookservice.getOrderListByDateInfoById(order);
	}
	
	
	@ResponseBody
	@RequestMapping(value="/updateOrderStatusL")
	public List<OrderL> updateOrderStatus(@RequestBody OrderL order){
		cookservice.updateOrderStatus(order);
		OrderL orderL = new OrderL();
		orderL.setOrder_status("未审核");
		List<OrderL> list = cookservice.getOrderListNoCheck();
		return list;
		
	}
}
